package com.tanhua.server.exception;

import com.tanhua.model.vo.ErrorResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice  //声明异常处理类  让spring知道
public class ExceptionAdvice {
    @ExceptionHandler(Exception.class)
    public ResponseEntity handlerException(Exception e){
        e.printStackTrace();
        Map remap = new HashMap();
        remap.put("errorCode",10001);
        remap.put("errorMeesage","对不起我错了");
        return ResponseEntity.status(500).body(remap);//指定响应数据

    }
    @ExceptionHandler(BusinessException.class)
   public ResponseEntity handlerBusinessException(BusinessException e){
        e.printStackTrace();
        ErrorResult vo = e.getVo();
        return ResponseEntity.status(500).body(vo);
   }
}
